//-------------------------------------------------------------------------------------
//feed and pet your pet
function feedandpet()
{

/*
******************************************pet health no longer on index
		if (location.href.indexOf("index.php")!=-1) {
			//check if pet energy or happiness is running low
			var divbars = document.evaluate("//div[@class='tg_eb_fill']",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
			petenergy = parseInt(divbars.snapshotItem(0).style.width.replace('%',''));
			pethappy  = parseInt(divbars.snapshotItem(1).style.width.replace('%',''));
			feedenergy = parseInt((((100-petenergy)-((100-petenergy) % 20)) / 20)*2);
		if ((pethappy<=50) || ((petenergy<=50) && (energy>=feedenergy))) {
				document.location = 'http://apps.facebook.com/'+SCRIPT.name+'/pet.php';
			}
		}
******************************************pet health no longer on index
*/
	if (location.href.indexOf('pet.php')!=-1)
		{
		//check pet energy and happiness levels again
		var divbars = document.evaluate("//div[@class='tg_eb_fill']",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
		petenergy = parseInt(divbars.snapshotItem(1).style.width.replace('%',''));
		pethappy  = parseInt(divbars.snapshotItem(2).style.width.replace('%',''));
		petenergyform = document.evaluate("//input[@value='Feed']",document,null,9,null).singleNodeValue;
		pethappyform = document.evaluate("//input[@value='Pet']",document,null,9,null).singleNodeValue;
		if ((petenergy>=60) && (pethappy>60))
			{
				petvisit = petvisit + 25 // no reason to burn all our energy right now, make a pass through then come back in a bit to top up more
				//---------------  Store pet visit value for next page load
				GM_setValue('petvisit', petvisit);
			}
		if ((petenergy<=80) && (energy>=2))
			{
				addToLog('Pet energy below 80%, currently '+petenergy+'%. Feeding...');
				petenergyform.click();
			} 
		else if ((petenergy<=80) && (energy<2))
			{
//				addToLog('Pet energy below 80%, currently '+pethappy+'%. But you're out of energy, coming back later');
				petvisit = petvisit + 10; // come back after a few cycles, let logic drop through
				//---------------  Store pet visit value for next page load
				GM_setValue('petvisit', petvisit);

			}
		else if (pethappy<80) 
			{
				addToLog('Pet happiness below 100%, currently '+pethappy+'%. Petting...');
				pethappyform.click();
			}
		else
			{
				addToLog('Pet stats ok');
				petvisit = petvisitfrequency;
				//---------------  Store pet visit value for next page load
				GM_setValue('petvisit', petvisit);
			}
		}
	else
		{
			window.location = "http://apps.facebook.com/"+SCRIPT.name+"/pet.php";
			flag = 1;
		}
}

